<template>
  <div>
    <el-row>
      <el-col :span="24" style="text-align:center;margin-top:50px;">
        <span>电影：</span>
        <el-select v-model="MoID" placeholder="请选择电影">
          <el-option
            v-for="item in MoiveInfo"
            :key="item.MovieID"
            :label="item.MovieName"
            :value="item.MovieID"
          ></el-option>
        </el-select>
      </el-col>
      <el-col :span="24" style="text-align:center;margin-top:50px;">
        <span>影厅：</span>
        <el-select v-model="HaID" placeholder="请选择影厅">
          <el-option
            v-for="item in HallInfo"
            :key="item.HallID"
            :label="item.HallName"
            :value="item.HallID"
          ></el-option>
        </el-select>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24" style="text-align:center;margin-top:50px;">
        <span>票价：</span>
        <el-input v-model="Price1" style="width:42%;" placeholder="请输入价格"></el-input>
      </el-col>
      <el-col :span="24" style="text-align:center;margin-top:50px;">
        <span>开始时间：</span>
        <el-date-picker
          v-model="StartTime1"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期时间"
        ></el-date-picker>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24" style="text-align:center;margin-top:50px;">
        <el-button type="primary" @click="AddSch()" round>排片</el-button>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      MoiveInfo: [],
      MoID: "",
      HallInfo: [],
      HaID: "",
      Price1: "",
      StartTime1: ""
    };
  },
  created() {
    this.Ajax.get("api/MovieInfoes/GetMovieInfo").then(M => {
      this.MoiveInfo = M.data;
    });
    this.Ajax.get("api/Hall/GetHall").then(H => {
      this.HallInfo = H.data;
    });
  },
  methods: {
    AddSch() {
      this.Ajax.post("api/Schedule/AddSchedule", {
        data: {
          MovieID: this.MoID,
          HallID: this.HaID,
          Price: this.Price1,
          StartTime: this.StartTime1
        }
      }).then(s => {
        if (s.data == 2) {
          this.$notify({
            title: "成功",
            message: "添加成功",
            type: "success"
          });
          window.location.reload();
        } else if (s.data == 1) {
          this.$notify({
            title: "警告",
            message: "该影厅此时间段有电影了，你想干嘛？",
            type: "warning"
          });
        } else if (s.data == 4) {
          this.$notify({
            title: "警告",
            message: "还未上映，不能排片",
            type: "warning"
          });
        } else if (s.data == 5) {
          this.$notify({
            title: "警告",
            message: "排片日期不能小于当前日期",
            type: "warning"
          });
        } else {
          this.$notify.error({
            title: "错误",
            message: "添加失败"
          });
        }
      });
    }
  }
};
</script>
<style></style>
